import { useLocation, Navigate } from 'react-router-dom'
import { getCookie } from '../utils'

// 路由白名单
const whiteList = ['/login', '/register']

// 路由拦截
const BeforeEach = (props: { children: JSX.Element }) => {
    const location = useLocation()
    if (!getCookie() && !whiteList.includes(location.pathname)) {
        return <Navigate to="/login" />
    }
    return props.children
}

export default BeforeEach